/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.gbvbahia.vendas.modelos;

import br.com.gbvbahia.vendas.modelos.enums.TipoTelefone;
import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

/**
 *
 * @author guilherme
 */
@Entity
@NamedQuery(name = "Telefone.autoCompleteMatricula",
        query = "SELECT distinct s.telefone FROM Telefone s "
        + " WHERE (:telefone is null OR "
        + " s.telefone LIKE :telefone)")
@Table(name = "telefone")
public class Telefone implements Serializable {

    private static final long serialVersionUID = 1L;
    /**
     *
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    /**
     *
     */
    @NotNull(message = "Informe o DDD")
    @Column(name = "ddd", nullable = false)
    private String ddd = "85";
    /**
     *
     */
    @NotNull(message = "Informe o Telefone")
    @Column(name = "telefone", nullable = false)
    private String telefone;
    /*
     * 
     */
    @NotNull(message = "O tipo de telefone deve ser informado")
    @Enumerated(EnumType.STRING)
    @Column(name = "tipo_telefone", nullable = false)
    private TipoTelefone tipo;
    /*
     * 
     */
    @Transient
    private boolean marcado;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 47 * hash + Objects.hashCode(this.ddd);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Telefone other = (Telefone) obj;
        if (!Objects.equals(this.ddd, other.ddd)) {
            return false;
        }
        if (!Objects.equals(this.telefone, other.telefone)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "(" + this.ddd + ")" + this.telefone;
    }
    
    public String getLabel(){
        return toString();
    }

    public String getDdd() {
        return ddd;
    }

    public void setDdd(String ddd) {
        this.ddd = ddd;
    }

    public String getTelefone() {
        return telefone;
    }

    public void setTelefone(String telefone) {
        this.telefone = telefone;
    }

    public TipoTelefone getTipo() {
        return tipo;
    }

    public void setTipo(TipoTelefone tipo) {
        this.tipo = tipo;
    }

    public boolean isMarcado() {
        return marcado;
    }

    public void setMarcado(boolean marcado) {
        this.marcado = marcado;
    }
}
